/*
 * This is where the war stats are calculated
 */

package Current;

import java.io.Serializable;

/**
 * @author Fork
 */
public class WarStats implements Serializable, Cloneable {

    private Integer Offense;
    private Integer Defense;
    private Integer SpyOffense;
    private Integer SpyDefense;

    public WarStats(UnitTraining Units, ProeficiencyPoints Points, StructureUpgrades Structures, Race Race, ClassDT Class, Armories Armories, BattleUpgrades battleUpgrades) {
        this.Offense = calcOffense(Race, Class, Units, Points, Structures, Armories, battleUpgrades);
        this.Defense = calcDefense(Race, Class, Units, Points, Structures, Armories, battleUpgrades);
        this.SpyOffense = calcSpyOffense(Race, Class, Units, Points, Structures, Armories);
        this.SpyDefense = calcSpyDefense(Race, Class, Units, Points, Structures, Armories);
    }

    Integer calcOffense(Race Race, ClassDT ClassDT, UnitTraining Units, ProeficiencyPoints Points, StructureUpgrades Structures, Armories Armories, BattleUpgrades battleUpgrades) {
        Integer aux;
        Double multiplier;
        Double result;


        aux = Units.getOffenseFromSoldiers() + Armories.getOffenseBonusFromArmory() + battleUpgrades.getOffenseBonusFromUpgrades();
        multiplier = 1 + ((double) Race.offenseBoost() + ClassDT.offenseBoost() + Points.getStrength() + Structures.getOffFortBonus()) / 100;

        result = aux * multiplier;

        result = Math.rint(result);

        return result.intValue();
    }

    Integer calcDefense(Race Race, ClassDT Class, UnitTraining Units, ProeficiencyPoints Points, StructureUpgrades Structures, Armories armories, BattleUpgrades battleUpgrades) {
        Integer aux;
        Double multiplier;
        Double result;

        aux = Units.getDefenseFromGuards() + armories.getDefenseBonusFromArmory() + battleUpgrades.getDefenseBonusFromUpgrades();
        multiplier = 1 + ((double) Race.defenseBoost() + Class.defenseBoost() + Points.getConstitution() + Structures.getDefenseBonus()) / 100;

        result = aux * multiplier;

        result = Math.rint(result);

        return result.intValue();
    }

    Integer calcSpyOffense(Race Race, ClassDT Class, UnitTraining Units, ProeficiencyPoints Points, StructureUpgrades Structures, Armories armories) {
        Integer aux;
        Double multiplier;
        Double result;

        aux = Units.getSpyOffenseFromSpies() + armories.getSpyOffenseBonusFromArmory();
        multiplier = 1 + ((double) Race.spyOffenseBoost() + Class.spyOffenseBoost() + Points.getIntelligence() + Structures.getSpyOffFortBonus()) / 100;

        result = aux * multiplier;

        result = Math.ceil(result);

        return result.intValue();
    }

    Integer calcSpyDefense(Race Race, ClassDT Class, UnitTraining Units, ProeficiencyPoints Points, StructureUpgrades Structures, Armories armories) {
        Integer aux;
        Double multiplier;
        Double result;

        aux = Units.getSpyDefenseFromSentries() + armories.getSpyDefenseBonusFromArmory();
        multiplier = 1 + ((double) Race.spyDefenseBoost() + Class.spyDefenseBoost() + Points.getIntelligence() + Structures.getSpyDefFortBonus()) / 100;

        result = aux * multiplier;

        result = Math.ceil(result);

        return result.intValue();
    }

    public void refreshStats(Race Race, ClassDT Class, UnitTraining Units, ProeficiencyPoints Points, StructureUpgrades Structures, Armories armories, BattleUpgrades battleUpgrades) {
        setOffense(calcOffense(Race, Class, Units, Points, Structures, armories, battleUpgrades));
        setDefense(calcDefense(Race, Class, Units, Points, Structures, armories, battleUpgrades));
        setSpyOffense(calcSpyOffense(Race, Class, Units, Points, Structures, armories));
        setSpyDefense(calcSpyDefense(Race, Class, Units, Points, Structures, armories));
    }

    public Integer getDefense() {
        return Defense;
    }

    void setDefense(Integer Defense) {
        this.Defense = Defense;
    }

    public Integer getOffense() {
        return Offense;
    }

    void setOffense(Integer Offense) {
        this.Offense = Offense;
    }

    public Integer getSpyDefense() {
        return SpyDefense;
    }

    void setSpyDefense(Integer SpyDefense) {
        this.SpyDefense = SpyDefense;
    }

    public Integer getSpyOffense() {
        return SpyOffense;
    }

    void setSpyOffense(Integer SpyOffense) {
        this.SpyOffense = SpyOffense;
    }
}
